<?php

header("Content-type:text/html; charset='utf8'");

set_time_limit(0);

require_once("system\db\mysql_pdo.php");

require_once("system\model\model.php");

require_once("system\lib\Snoopy.class.php");

$snoopy = new Snoopy();

/*
 *	采集添加剂信息
 *  1.采集www.xuanfood.com/zymc/tjj/list_61_1.html-www.xuanfood.com/zymc/tjj/list_61_8.html的链接
 *	2.分别进入具体页面进行采集：
 *		1.将添加剂的中文名，功能，adi存入food_additive表，返回添加剂的id值。
 *		2.利用id将添加剂的安全性存入food_additive_security中。
 *		3.将类别存入food_additive_category中，返回类别的id，
 *		4.依据添加剂的id值和类别的id，更新food_additive_category_rel。
		5.将最大使用量区间的食品种类存入food_category表，返回其id
		5.根据食品种类id和添加剂id，再结合页面上最大使用量值存入food_maxuse表，
	
	采集食品信息
	1.采集www.xuanfood.com/biaoqianjiedu/的所有连接，并将其分类名存入food_category表，返回其种类id。
	2.进入第二级页面进行采集链接
	3.进入具体页面进行信息采集，依据种类id，将食品名称，条形码，图片，种类id存入food_basic表，返回食品id
	4.依据页面上的添加剂查询food_additive表，返回所查询添加剂的id和食品id，在food_basic_additive_rel表   中建立与食品id的联系。
	5.将配料存入food_batching表中，返回其配料id，结合食品id，在food_basic_batching_rel表中建立联系
	6.将营养成分类别存入food_nutrition_category表，返回其id。依据食品id和营养成分id将营养成分存入
	  food_basic_nutrition_rel表，建立联系。
	7.依据最大使用量的食品种类，查询种类id是否存在，if不存在，则存入food_category表，并返回其id,else      返回其id。
	
 
	*/					
	
	//采集添加剂页面的所有链接
/*     $urlLink = "http://www.xuanfood.com/zymc/tjj/list_61_8.html";
	$snoopy->fetchlinks($urlLink);   
	$url=array();   
	$url=$snoopy->results; 
	//print_r($url); 
	
	//去除不相关的url
	foreach($url as $key=>$value)   
    {   
		//http://www.xuanfood.com/zymc/tjj/qt/2011/0804/1070.html	
        if (!preg_match("/http:\/\/www\.xuanfood\.com\/zymc\/tjj\/[a-zA-Z]{1,6}\/[1-9]{1,6}/i",$value))   
        {   
            unset($url[$key]);   
        }   
    }   
	print_r($url);  
 */
$url =array(
'http://www.xuanfood.com/zymc/tjj/sfbcj/2011/0606/209.html', 
'http://www.xuanfood.com/zymc/tjj/js/2011/0803/1017.html', 
'http://www.xuanfood.com/zymc/tjj/mfclj/2011/0606/155.html', 
'http://www.xuanfood.com/zymc/tjj/mfclj/2011/0606/159.html', 
'http://www.xuanfood.com/zymc/tjj/mfclj/2011/0606/154.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0804/1061.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0804/1060.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0606/153.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0606/152.html', 
'ttp://www.xuanfood.com/zymc/tjj/syxl/2011/0606/151.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0606/150.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0606/149.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0606/148.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0606/147.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0606/146.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0606/145.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0606/144.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0606/143.html', 
'http://www.xuanfood.com/zymc/tjj/syxl/2011/0606/142.html', 
'http://www.xuanfood.com/zymc/tjj/js/2011/0803/1015.html', 
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0606/140.html', 
'http://www.xuanfood.com/zymc/tjj/js/2011/0803/997.html', 
'http://www.xuanfood.com/zymc/tjj/qt/2011/0804/1068.html', 
'http://www.xuanfood.com/zymc/tjj/qt/2011/0804/1069.html', 
'http://www.xuanfood.com/zymc/tjj/qt/2011/0804/1070.html', 
'http://www.xuanfood.com/zymc/tjj/qt/2011/0804/1072.html', 
'http://www.xuanfood.com/zymc/tjj/qt/2011/0804/1071.html', 
'http://www.xuanfood.com/zymc/tjj/qt/2011/0804/1073.html', 
'http://www.xuanfood.com/zymc/tjj/qt/2011/0804/1074.html', 
'http://www.xuanfood.com/zymc/tjj/qt/2011/0804/1075.html',
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0821/1379.html', 
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0821/1378.html', 
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0821/1377.html', 
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0606/133.html', 
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0606/138.html', 
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0606/136.html', 
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0821/1376.html', 
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0606/141.html', 
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0606/137.html'. 
'http://www.xuanfood.com/zymc/tjj/sdtjj/2011/0606/101.html', 
'http://www.xuanfood.com/zymc/tjj/sdtjj/2011/0804/1057.html', 
'http://www.xuanfood.com/zymc/tjj/sdtjj/2011/0804/1058.html', 
'http://www.xuanfood.com/zymc/tjj/sdtjj/2011/0804/1059.html', 
'http://www.xuanfood.com/zymc/tjj/sdtjj/2011/0804/1066.html', 
'http://www.xuanfood.com/zymc/tjj/sdtjj/2011/0804/1067.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0606/127.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0606/131.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0804/1064.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0804/1065.html', 
'http://www.xuanfood.com/zymc/tjj/twj/2011/0606/111.html', 
'http://www.xuanfood.com/zymc/tjj/twj/2011/0703/755.html', 
'http://www.xuanfood.com/zymc/tjj/twj/2011/0703/756.html', 
'http://www.xuanfood.com/zymc/tjj/pbj/2011/0804/1053.html', 
'http://www.xuanfood.com/zymc/tjj/pbj/2011/0804/1054.html', 
'http://www.xuanfood.com/zymc/tjj/pbj/2011/0804/1055.html', 
'http://www.xuanfood.com/zymc/tjj/zwj/2011/0606/95.html', 
'http://www.xuanfood.com/zymc/tjj/mfclj/2011/0606/157.html', 
'http://www.xuanfood.com/zymc/tjj/mfclj/2011/0606/156.html',
'http://www.xuanfood.com/zymc/tjj/kjj/2011/0606/160.html', 
'http://www.xuanfood.com/zymc/tjj/kjj/2011/0606/161.html',
'http://www.xuanfood.com/zymc/tjj/pbj/2011/0606/90.html',
'http://www.xuanfood.com/zymc/tjj/wdhngj/2011/0606/222.html',
'http://www.xuanfood.com/zymc/tjj/wdhngj/2011/0606/225.html',
'http://www.xuanfood.com/zymc/tjj/wdhngj/2011/0606/223.html',
'http://www.xuanfood.com/zymc/tjj/wdhngj/2011/0606/226.html',
'http://www.xuanfood.com/zymc/tjj/bmj/2011/0606/202.html', 
'http://www.xuanfood.com/zymc/tjj/bmj/2011/0606/204.html', 
'http://www.xuanfood.com/zymc/tjj/bmj/2011/0606/205.html', 
'http://www.xuanfood.com/zymc/tjj/bmj/2011/0606/207.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/186.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/192.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/193.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/195.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/194.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/197.html', 
'http://www.xuanfood.com/zymc/tjj/psj/2011/0606/179.html', 
'http://www.xuanfood.com/zymc/tjj/psj/2011/0606/180.html', 
'http://www.xuanfood.com/zymc/tjj/psj/2011/0606/178.html', 
'http://www.xuanfood.com/zymc/tjj/sfbcj/2011/0804/1078.html', 
'http://www.xuanfood.com/zymc/tjj/sfbcj/2011/0804/1076.html', 
'http://www.xuanfood.com/zymc/tjj/sfbcj/2011/0606/218.html', 
'http://www.xuanfood.com/zymc/tjj/sfbcj/2011/0606/214.html', 
'http://www.xuanfood.com/zymc/tjj/hsj/2011/0804/1079.html', 
'http://www.xuanfood.com/zymc/tjj/hsj/2011/0804/1080.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0804/1081.html', 
'http://www.xuanfood.com/zymc/tjj/kjj/2011/0804/1063.html', 
'http://www.xuanfood.com/zymc/tjj/kjj/2011/0804/1083.html', 
'http://www.xuanfood.com/zymc/tjj/kjj/2011/0606/165.html', 
'http://www.xuanfood.com/zymc/tjj/jmtjcj/2011/0804/1082.html', 
'http://www.xuanfood.com/zymc/tjj/jmtjcj/2011/0606/182.html',
'http://www.xuanfood.com/zymc/tjj/xpj/2011/0606/170.html', 
'http://www.xuanfood.com/zymc/tjj/xpj/2011/0606/169.html', 
'http://www.xuanfood.com/zymc/tjj/xpj/2011/0606/172.html', 
'http://www.xuanfood.com/zymc/tjj/xpj/2011/0606/167.html', 
'http://www.xuanfood.com/zymc/tjj/xpj/2011/0606/166.html', 
'http://www.xuanfood.com/zymc/tjj/sdtjj/2011/0606/102.html', 
'http://www.xuanfood.com/zymc/tjj/pbj/2011/0606/90.html', 
'http://www.xuanfood.com/zymc/tjj/js/2011/0803/1006.html', 
'http://www.xuanfood.com/zymc/tjj/twj/2011/0606/110.html', 
'http://www.xuanfood.com/zymc/tjj/zwj/2011/0606/92.html', 
'http://www.xuanfood.com/zymc/tjj/kyhj/2011/0606/83.html', 
'http://www.xuanfood.com/zymc/tjj/kyhj/2011/0606/84.html', 
'http://www.xuanfood.com/zymc/tjj/kyhj/2011/0617/616.html',
'http://www.xuanfood.com/zymc/tjj/mfclj/2011/0606/158.html', 
'http://www.xuanfood.com/zymc/tjj/wdhngj/2011/0606/228.html', 
'http://www.xuanfood.com/zymc/tjj/wdhngj/2011/0606/224.html', 
'http://www.xuanfood.com/zymc/tjj/sfbcj/2011/0606/217.html', 
'http://www.xuanfood.com/zymc/tjj/sfbcj/2011/0606/216.html', 
'http://www.xuanfood.com/zymc/tjj/sfbcj/2011/0606/215.html', 
'http://www.xuanfood.com/zymc/tjj/sfbcj/2011/0606/213.html', 
'http://www.xuanfood.com/zymc/tjj/sfbcj/2011/0606/212.html', 
'http://www.xuanfood.com/zymc/tjj/sfbcj/2011/0606/211.html', 
'http://www.xuanfood.com/zymc/tjj/sfbcj/2011/0606/210.html', 
'http://www.xuanfood.com/zymc/tjj/hsj/2011/0606/199.html', 
'http://www.xuanfood.com/zymc/tjj/hsj/2011/0606/200.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/198.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/191.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/185.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/183.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/189.html', 
'http://www.xuanfood.com/zymc/tjj/jmtjcj/2011/0606/181.html', 
'http://www.xuanfood.com/zymc/tjj/psj/2011/0606/176.html', 
'http://www.xuanfood.com/zymc/tjj/psj/2011/0606/175.html', 
'http://www.xuanfood.com/zymc/tjj/kjj/2011/0606/162.html', 
'http://www.xuanfood.com/zymc/tjj/kjj/2011/0606/163.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/59.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/60.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/61.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/62.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/63.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/64.html',
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/65.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/66.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/72.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/73.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/74.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0606/121.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0606/122.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0606/125.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0606/126.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0606/124.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0606/123.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0606/128.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0606/130.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0606/120.html', 
'http://www.xuanfood.com/zymc/tjj/zcj/2011/0606/129.html', 
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0606/139.html', 
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0606/134.html', 
'http://www.xuanfood.com/zymc/tjj/rhj/2011/0606/135.html', 
'http://www.xuanfood.com/zymc/tjj/mzj/2011/0703/749.html', 
'http://www.xuanfood.com/zymc/tjj/mzj/2011/0703/748.html', 
'http://www.xuanfood.com/zymc/tjj/mzj/2011/0703/747.html', 
'http://www.xuanfood.com/zymc/tjj/mzj/2011/0606/119.html', 
'http://www.xuanfood.com/zymc/tjj/mzj/2011/0606/118.html', 
'http://www.xuanfood.com/zymc/tjj/mzj/2011/0606/117.html', 
'http://www.xuanfood.com/zymc/tjj/mzj/2011/0606/116.html', 
'http://www.xuanfood.com/zymc/tjj/mzj/2011/0606/115.html', 
'http://www.xuanfood.com/zymc/tjj/mzj/2011/0606/114.html', 
'http://www.xuanfood.com/zymc/tjj/mzj/2011/0606/113.html', 
'http://www.xuanfood.com/zymc/tjj/twj/2011/0703/758.html', 
'http://www.xuanfood.com/zymc/tjj/twj/2011/0606/108.html', 
'http://www.xuanfood.com/zymc/tjj/twj/2011/0606/109.html',
'http://www.xuanfood.com/zymc/tjj/twj/2011/0606/107.html', 
'http://www.xuanfood.com/zymc/tjj/twj/2011/0606/112.html', 
'http://www.xuanfood.com/zymc/tjj/twj/2011/0606/106.html', 
'http://www.xuanfood.com/zymc/tjj/twj/2011/0606/105.html', 
'http://www.xuanfood.com/zymc/tjj/twj/2011/0606/104.html', 
'http://www.xuanfood.com/zymc/tjj/twj/2011/0606/103.html', 
'http://www.xuanfood.com/zymc/tjj/sdtjj/2011/0606/100.html', 
'http://www.xuanfood.com/zymc/tjj/sdtjj/2011/0606/99.html', 
'http://www.xuanfood.com/zymc/tjj/sdtjj/2011/0606/98.html', 
'http://www.xuanfood.com/zymc/tjj/sdtjj/2011/0606/97.html', 
'http://www.xuanfood.com/zymc/tjj/sdtjj/2011/0606/96.html', 
'http://www.xuanfood.com/zymc/tjj/zwj/2011/0606/94.html', 
'http://www.xuanfood.com/zymc/tjj/zwj/2011/0606/93.html', 
'http://www.xuanfood.com/zymc/tjj/zwj/2011/0606/91.html', 
'http://www.xuanfood.com/zymc/tjj/pbj/2011/0606/88.html', 
'http://www.xuanfood.com/zymc/tjj/pbj/2011/0606/89.html', 
'http://www.xuanfood.com/zymc/tjj/pbj/2011/0702/741.html', 
'http://www.xuanfood.com/zymc/tjj/kyhj/2011/0606/87.html', 
'http://www.xuanfood.com/zymc/tjj/kyhj/2011/0606/82.html', 
'http://www.xuanfood.com/zymc/tjj/kyhj/2011/0606/81.html', 
'http://www.xuanfood.com/zymc/tjj/kyhj/2011/0606/80.html', 
'http://www.xuanfood.com/zymc/tjj/kyhj/2011/0606/79.html', 
'http://www.xuanfood.com/zymc/tjj/kyhj/2011/0606/78.html', 
'http://www.xuanfood.com/zymc/tjj/kyhj/2011/0606/77.html', 
'http://www.xuanfood.com/zymc/tjj/kyhj/2011/0606/76.html', 
'http://www.xuanfood.com/zymc/tjj/kyhj/2011/0606/75.html', 
'http://www.xuanfood.com/zymc/tjj/wdhngj/2011/0606/219.html', 
'http://www.xuanfood.com/zymc/tjj/wdhngj/2011/0606/220.html', 
'http://www.xuanfood.com/zymc/tjj/bmj/2011/0606/206.html',
'http://www.xuanfood.com/zymc/tjj/bmj/2011/0606/203.html',
'http://www.xuanfood.com/zymc/tjj/bmj/2011/0606/201.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/184.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/187.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/188.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/190.html', 
'http://www.xuanfood.com/zymc/tjj/zsj/2011/0606/196.html', 
'http://www.xuanfood.com/zymc/tjj/psj/2011/0606/177.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0605/51.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/68.html', 
'http://www.xuanfood.com/zymc/tjj/jgzj/2011/0606/242.htm', 
'http://www.xuanfood.com/zymc/tjj/jgzj/2011/0606/241.htm', 
'http://www.xuanfood.com/zymc/tjj/jgzj/2011/0606/240.htm', 
'http://www.xuanfood.com/zymc/tjj/jgzj/2011/0606/238.htm', 
'http://www.xuanfood.com/zymc/tjj/jgzj/2011/0606/237.htm', 
'http://www.xuanfood.com/zymc/tjj/jgzj/2011/0606/235.htm', 
'http://www.xuanfood.com/zymc/tjj/jgzj/2011/0606/234.htm', 
'http://www.xuanfood.com/zymc/tjj/jgzj/2011/0606/232.htm', 
'http://www.xuanfood.com/zymc/tjj/jgzj/2011/0606/231.htm', 
'http://www.xuanfood.com/zymc/tjj/jgzj/2011/0606/230.htm', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/71.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/70.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/69.html', 
'http://www.xuanfood.com/zymc/tjj/ffj/2011/0606/67.html',
'http://www.xuanfood.com/zymc/tjj/xpj/2011/0606/173.html' 
); 
	
	foreach ($url as $key=>$value)   
	{   
        $snoopy=new Snoopy();   
        $snoopy->fetch($value);   
        $content=array();   
        $content=$snoopy->results;   
       // print_r($content);     
			
		//读取页面信息
		//匹配添加剂名称
		if(preg_match_all("/<h2>(.*?)<\/h2>/is",$content,$ti))
		{
			//print_r($ti[0][0]);
			
			//检验是否存在别名
			if(preg_match_all("/(.*?)\（(.*?)\）/is",DeleteHtml($ti[1][0]),$vv))
			{
				//print_r($vv);
				$additive_ch_name= $vv[1][0];
				$additive_bm = $vv[2][0];
			}
			else
			{
				$additive_ch_name= DeleteHtml($ti[1][0]);
			}
	
			if(preg_match_all("/<td>(.*?)<\/td>/is",$content,$tt))
			{
				//print_r($tt[1]);
			
				//添加剂adi
				echo $adi = substr(DeleteHtml($tt[1][5]),20,27);
				$patterns = "/\d+/";
				preg_match_all($patterns,$adi,$arr);
				
				print_r($arr);
				//判断adi值是否存在
				if(@is_numeric($arr[0][2]) && isset($arr[0][2]))
				{
					echo $additive_adi = $arr[0][1].'.'.$arr[0][2];
				}
				elseif(@is_numeric($arr[0][1]) && !isset($arr[0][2]) && isset($arr[0][1]))
				{
					echo $additive_adi = $arr[0][1];
				}
				else
				{
					$additive_adi = 0;
					echo 'ADI 不存在'."<br/>";
				}
				// print_r($arr);
				
				//添加剂功能
				$additive_func = DeleteHtml($tt[1][7]);
				
				//将添加剂名称，功能，adi值存入food_additive表，返回添加剂的id值
				echo $additive_id = saveAdditiveInfor($additive_ch_name,$additive_bm = null,$additive_adi,$additive_func,$dbh);
				echo "<br />";
				//添加剂安全性
			
				$additive_secu = $tt[1][5];
				preg_match_all("/<p>(.*?)<\/p>/is",$additive_secu,$secu);
				//count($secu[0]);
				foreach($secu[0] as $secuk=>$secuv)
				{
					$additive_security = DeleteHtml($secuv);

					//将添加剂的安全信息存入food_additiv_security表
					saveAdditiveSecurity($additive_id,$additive_security,$dbh);
				}
				
				//添加剂类别
				$additive_category[] = DeleteHtml($tt[1][3]);
				//print_r($additive_category);
				
				$additive_category_v1[] = explode("，",$additive_category[0]);
				//print_r($additive_category_v1);
				
				foreach($additive_category_v1[0] as $k2=>$v2)
				{
					$acAnd[] = explode('和',$v2);
				}
				//print_r($acAnd);
				
				foreach($acAnd as $k4=>$v4)
				{
					foreach($v4 as $k5=>$v5)
					{
						$acAndAdd[] = explode('、',$v5);
					}
				}
				
				foreach($acAndAdd as $kw=>$vw)
				{
					foreach($vw as $kn=>$vn)
					{
						//将添加剂信息类别信息存入food_additive_category
						$additive_category_id = saveAdditiveCategory($vn,$dbh);
						
						//建立添加剂类别与添加剂之间的联系
						//echo $additive_id;
						saveAdditiveCategoryRel($additive_id,$additive_category_id,$dbh);
					}
				}
				//print_r($acAndAdd);
				unset($additive_category);
				unset($additive_category_v1);
				unset($acAnd);
				unset($acAndAdd);
			}//end if td
		}//end if h2

	}//end foreach url
		 
		 
	
	
	
	
	
	
	
	
	/* 
		 //读取最大使用量
		preg_match_all("/<p>(.*?)<\/p>/is",$content,$maxuse); 
		
		//去除数组内多余的html标签，空格等
		foreach($maxuse[0] as $k=>$v)
		{
			$maxuseDelTags[] = DeleteHtml($v);
		}
		
		//去除空的数组元素
		$maxuseDelTags = array_filter($maxuseDelTags);
		
		print_r($maxuseDelTags);
		//echo "<hr>";
		//$maxuseCount = count($maxuseDelTags);
		
		$startKey = (int)getMaxuseStartKey($maxuseDelTags) + 1;
		
		if($startKey > 1)
		{
			foreach($maxuseDelTags as $maxk1=>$maxv1)
			{
				if($startKey < $maxk1)
				{
					$maxuseUn[] = explode("，",$maxv1);	
				}
			}
			
			//print_r($maxuseUn);
			//echo "<hr>";
			
			foreach($maxuseUn as $k6=>$v6)
			{
				foreach($v6 as $k7=>$v7)
				{
					$maxuseUnDian[] = explode('和',$v7);
				}
			}
			
			//print_r($maxuseUnDian);
			//echo "<hr>";
			
		
			foreach($maxuseUn as $unK=>$unV)
			{
				//print_r($unV);
				(int)$unVCount = (int)count($unV) - 1;

				//最大使用量值
				$unVmaxuse = $unV[$unVCount];
				
				if($unVmaxuse == '最大使用量为按生产需要适量使用')
				{
					//最大使用量为按生产需要适量使用
					$MaxuseValue = 1000;
					//echo '这些没有具体的最大使用量值,默认设置为1000'."<br/>";
				}
				else
				{
					//最大使用量存在
					preg_match_all("/(([0-9]+[\.]?[0-9]+)|[1-9])/",$unVmaxuse,$edVmaxuse);
					$edMaxuseValue = array_unique($edVmaxuse);
					$MaxuseValue = $edMaxuseValue[0][0];
				}
				//	echo "<br>";echo "<br>";echo "<br>";
					//print_r($MaxuseValue);echo "<br>";echo "<br>";echo "<br>";
					//循环食品种类
					$maxuseArr = array();
					
					for($i=0;$i<$unVCount;$i++)
					{
						if(preg_match_all("/(.*?)\（(.*?)\）/is",$unV[$i],$vv))
						{
							//print_r($vv[1][0]);
							$maxuseArr[] = $vv[1][0];
						}
						else
						{	//echo $unV[$i];
							$maxuseArr[] = $unV[$i];
						}
						
					}
					//echo "<hr>";
					//print_r($maxuseArr);

					foreach($maxuseArr as $k8=>$v8)
					{
						$maxuseUnA[] = explode('、',$v8);
					}

					//print_r($maxuseUnA);
		
					////将食品分类信息存入food_category中,返回其category_id
					foreach($maxuseUnA as $maxuseArr_k=>$maxuseArr_v)
					{
						foreach($maxuseArr_v as $maxuse_k=>$maxuse_v)
						{echo $maxuse_v;echo "<br>";
							//$category_id = saveFoodCategory($maxuse_v,$dbh);
						
							//将添加剂在各类食品中的最大使用量存入food_maxuse
							//echo $additive_id;
							//saveMaxuse($additive_id,$category_id,$MaxuseValue,$dbh);
						}
					} 
			}			
				//print_r($maxuseUn);
		}//end if > 1
		else
		{
			echo '不存在最大使用量开始键值';
		} */
					
 

	
/* if(!preg_match("/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u",$str,$v)) //UTF-8汉字字母数字下划线正则表达式
{  
      echo"<font color=red>您输入的[".$str."]含有违法字符</font>";  
}
else
{
       echo "<font color=green>您输入的[".$str."]完全合法,通过!</font>";  
}
	 */
	
	



?>